﻿﻿<?php
	if(1)
	{
		$username = $_POST["user"];
		$password = $_POST["password"];
		$confirm = $_POST["password1"];
		$email = $_POST["email"];
		if($username=="" || $password=="" || $confirm=="" || $email=="")
		{
			echo '<script>alert("请确认信息的完整性！");history.go(-1);</script>';	//为什么单引号和双引号不一样
		}
		else if($password != $confirm)
		{
			echo '<script>alert("密码不一致！");history.go(-1);</script>';
		}
		else
        {
			require("Include/conn.php");
			$sql = "SELECT `user_name` FROM `pw_user` WHERE `user_name`='$username';";
			$result = mysqli_query($link,$sql);
            if (!$result)
            {
                die(mysqli_error($link));
            }
            $num = mysqli_num_rows($result);
			if($num)
			{//说明该用户已经存在
				echo '<script>alert("该用户已存在，请登录！");history.go(-1);</script>';
			}
			else {
				require("Include/conn.php");

				$sql_insert = "INSERT INTO `pw_user` (`user_pwd`,`user_name`,`user_sign`,`user_email`,`user_likecnt`,`user_likedcnt`,`user_stat`) VALUES ('$password','$username','','$email',0,0,1);";
                $sql_insert = "CALL REGISTER_INFO('$username','$password','$email');";//调用存储过程
                $result_insert = mysqli_query($link,$sql_insert);
				if($result_insert){
					echo '<script>alert("注册成功！");window.location.href = \'index.php\';</script>';
				}
				else{
					echo '<script>alert("系统繁忙，请稍后！");window.location.href = \'register.php\';</script>';
				}
			}
		}
	}
	else{
		echo 'ifwrong';
	}
?>